import mailist from '../views/mai_list.vue'
import track_detail from  '../views/track_detail.vue'


/**
 * 工厂函数 服务端动态preFetch store里面数据
 * @param type
 * @returns {*}
 */
export function createListView (type, payload) {

  if (type == 'List') {
    return {
      name: type,
      // this will be called during SSR to pre-fetch data into the store!
      preFetch (store) {
        return store.dispatch('getMailist')
      },
      render (h) {
        return h(mailist)
      }
    }
  }
  else if (type == 'Detail') {
    return {
      name: type,
      // this will be called during SSR to pre-fetch data into the store!
      preFetch (store, context_url) {
        let reg = /nid=([0-9]{1,3})/;
        let nid = context_url.match(reg);
        return store.dispatch('getNodeDetail', nid[1])
      },
      render (h) {
        return h(track_detail)
      }
    }
  }

}
